from fastapi import Request, Response
from fastapi.routing import APIRoute
from afast_core.core_libs.classy_apirouter.group_router import RestInjectForAPIRouter, RestInjectForDocRouter
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from afast_core.core_libs.classy_apirouter import IHookGroupBaseController
from afast_core.core_libs.classy_apirouter import get, post
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.login.controllers.auth_login import AuthloginController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.login.controllers.auth_logout import \
    AuthlogOutController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.login.controllers.auth_route import AuthRouteController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.login.controllers.auth_user_info import \
    AuthUserInfoIController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.login.controllers.auth_captcha import CommonCaptchaImgController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.login.controllers.getLoginInfo import GetDupdateAuthloginController


#  tags=['测试类装饰器依赖项']

@RestInjectForAPIRouter(prefix='/auth')
@RestInjectForDocRouter(tags=['后台系统-登入和登出组模块'])
class AGroupAPIRouterBuilder(IHookGroupBaseController):
    # 定义公共全局的可用的服务，通过request对象进行透传当前的self

    async def before_request(self, curr_apiroute: APIRoute, request: Request) -> None:
        """如果需要修改请求信息，可直接重写此方法"""
        pass
        request.state.api_router_builder = self
        # 如果存在body对象的，在这里读取一下，以备后续的使用
        request.state.schema_param_body = await request.body()
        print("request.state.schema_param_body ", request.state.schema_param_body)

    async def after_request(self, request: Request, response: Response) -> None:
        """请求后的处理"""
        pass

    @get("/login/getCaptcha", summary='获取登入系统后台的的验证码')
    def admin_common_captcha_img(self, controller: IBaseController = CommonCaptchaImgController):
        '''
        获取医院信息接口

        :param appid: 医院商户编号ID

        :return:
        '''
        return controller.sync_response()

    @post("/login", summary='提交验证吗登入')
    def admin_auth_login(self, controller: IBaseController = AuthloginController):
        '''
        获取医院信息接口

        :param appid: 医院商户编号ID

        :return:
        '''
        return controller.sync_response()

    @get("/login/logout", summary='退出登入')
    def admin_auth_logout(self, controller: IBaseController = AuthlogOutController):
        '''
        获取医院信息接口

        :param appid: 医院商户编号ID

        :return:
        '''
        return controller.sync_response()

    @get("/login/getLoginInfo", summary='获取路由地址')
    def admin_auth_route_login_getLoginInfo(self, controller: IBaseController = GetDupdateAuthloginController):
        '''
        获取医院信息接口

        :param appid: 医院商户编号ID

        :return:
        '''
        return controller.sync_response()

    @get("/login/refresh", summary='刷新权限')
    def admin_auth_route_login_refresh(self, controller: IBaseController = GetDupdateAuthloginController):
        '''
        获取医院信息接口

        :param appid: 医院商户编号ID

        :return:
        '''
        return controller.sync_response()
